package com.dd.mapper;

import com.dd.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {
    // 用方法来写SQL语句  CRUD
    // 查询所有用户 ，网页显示列表
    @Select("select * from user")
    List<User> selectAllUsers();

    // 根据编号查用户 ， 网页要修改用户，先查这个用户，再回显到表单，
    @Select("select * from user where userId = #{id}")  // #自动判断类型 String id select * from user where userId = '10'
    User selectUserById(int id);

    // 根据编号删除用户，
    @Delete("delete from user where userId = #{id}")
    int deleteUserById(int id);

    // 添加新用户
    @Insert("insert into user (username) values (#{username})")
    int insertUser(User user);

    // 修改旧用户
    @Update("update user set username = #{username} where userId = #{userId}")
    int updateUser(User user);

    // 根据用户名查询用户，用来模糊查询,返回值
    @Select("select * from user where username like '%${username}%'")
    List<User> selectUserByName(String username);

}
